'use strict';

const getToken = require('../../business/getwebtoken.js');
const getUserInfo = require('../../business/getwebuserinfo.js');
import DBHelper from '../../business/db_helper.js';

var crypto=require('crypto');
export default class extends think.controller.base {



  /**
   * index action
   * @return {Promise} []
   */
  async indexAction(){



var _that=this;

try
{
  //微信登录回调
  getToken(this.param("code"))
    .then(function (data) {
		//console.log(JSON.parse(data));
      return JSON.parse(data);
      
    }).then(function (data) {
      //console.log("getUserInfo1");
      //console.log("access_token"+data['access_token']);
       getUserInfo(data['access_token'], data['openid']).then(  function (userinfo){
        //{ openid: 'oFZTB1b1TC0ud1zTnX7KOtE6RNpY',
        //nickname: '...',
        //sex: 1,
        //language: 'zh_CN',
        //city: '广州',
        //province: '广东',
        //country: '中国',
        //headimgurl: 'http://thirdwx.qlogo.cn/mmopen/vi_32/zWXSkANEsFM3ywJ1dnIQwtSgXuicwnne21sicbSkxaamj76kEamGBIsvK3F3D1A1ZYFynOzeYHBupnZVJ3Utwm7Q/132',
        //privilege: [],
        //unioonid: 'omQhcwkp-EpLtSwLUv-4XPjOgQe0' }
        var arr= JSON.stringify(userinfo);  
        console.log(arr);
        userinfo= JSON.parse(userinfo);
        var openid=userinfo['openid'];
        var unionid=userinfo['unionid'];
        var nickname=userinfo['nickname'];
//console.log(JSON.parse(userinfo));
        console.log(openid);
        console.log(unionid);
        console.log(nickname);

        //console.log("getUserInfo2");
        //console.log(JSON.parse(userinfo));
                      //this.json(["修复成功"]);
 
                        _that.display("");
                    
          });
      })

    }
    catch(err){ _that.display("");}
  }
}
